<template>
  <div style="overflow: auto">
    <div class="header">
      <el-form inline>
        <el-form-item label="用户名">
          <el-input v-model="searchName"></el-input>
        </el-form-item>

        <el-button @click="doGetSurveyModifys()">搜索</el-button>
      </el-form>
    </div>
    <div class="container">
      <el-table :data="modifys">
        <el-table-column
          width="80"
          label="编号"
          prop="DSSM_ID"
        ></el-table-column>
        <el-table-column
          width="100"
          label="姓名"
          prop="DSSV_Name"
        ></el-table-column>
        <el-table-column
          width="100"
          label="创建人"
          prop="USR_Name"
        ></el-table-column>
        <el-table-column
          label="提交时间"
          width="120"
          prop="DSSM_CreateDate"
        ></el-table-column>
        <el-table-column label="内容" prop="DSSM_Content"></el-table-column>

        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="mini" @click="toHandleModify(scope.row)">
              处理
            </el-button>
            <el-button
              v-if="!scope.row.DSSM_IsDone"
              size="mini"
              @click="doSurveyModifyDone(scope.row.DSSM_ID)"
            >
              完成
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page.sync="pageIndex"
        :total="total"
        :page-size.sync="pageSize"
        :page-sizes="[10, 20]"
        @size-change="
          (val) => {
            pageSize = val
            doGetSurveyModifys()
          }
        "
        @current-change="doGetSurveyModifys()"
      />
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

import { GetSurveyModifys, SurveyModifyDone } from '@/api/project/survey.js'

export default {
  components: {},
  computed: {
    ...mapGetters({
      curEmp: 'user/curEmp',
    }),
  },
  data: function () {
    return {
      searchName: null,
      total: 0,
      pageIndex: 1,
      pageSize: 10,
      step: 0,
      prjId: 0,
      modifys: [],
    }
  },
  methods: {
    toHandleModify(row) {
      this.$router.push({
        path: 'surveyDetail',
        query: { id: row.DSSM_SurveyID, prjId: row.DSSV_ProjectID },
      })
    },
    doGetSurveyModifys() {
      GetSurveyModifys(
        this.step,
        this.prjId,
        this.pageIndex,
        this.pageSize,
        this.searchName
      ).then((r) => {
        this.total = r.data.total
        this.modifys = r.data.datas
      })
    },
    doSurveyModifyDone: function (id) {
      var that = this
      that
        .$confirm('确认该修改意见已经完成？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          SurveyModifyDone(id).then((r) => {
            that.$message.success('已完成!')
            that.doGetSurveyModifys()
          })
        })
        .catch(() => {})
    },
  },
  created: function () {
    this.step = this.$route.query.step
    this.prjId = this.$route.query.prjId
  },
  mounted: function () {
    this.doGetSurveyModifys()
  },
}
</script>

<style scoped>
.header {
  padding: 20px;
}
.container {
  padding: 20px 10px;
}
.upload {
  margin-right: 15px;
}
</style>
